<!-- 通知公告详情 -->
<template>
	<view class="main-box">
		<!-- 顶部橙色标题栏 -->
		<view class="header-bar">
			<text class="back-icon" @click="goBack">←</text>
			<text class="header-title">通知详情</text>
		</view>
		<view class="main-box-header">
			<view class="header-label">
				{{formData.title}}
			</view>
			<view class="header-time">
				<text>{{formData.publisher||''}}</text>
				<uni-dateformat :date="formData.createTime"></uni-dateformat>
			</view>
		</view>
		<view class="main-box-content">
			<view class="content-value">
				<editor id="editor" v-model="editorinfo" class="ql-container" placeholder="开始输入..." showImgSize
					@statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady">
				</editor>
				<!-- <sv-wangeditor
				    v-model:html="formData.title2"
				    ref="editorRef"
				    mode="default"
				  ></sv-wangeditor> -->
			</view>
		</view>

		<template v-if="videoData && videoData.length > 0">
			<view class="main-box-content" v-for="(item, index) in videoData" :key="index">
				<view class="content-value">
					<video style="width: 100%;" :src="item" controls></video>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	import {
		videoTypes
} from "@/static/config.js";
import request from '@/common/request.js';
import {
	Platform,
	Storage_Key,
	CarSetting,
	timeslot
} from "@/static/config.js"
	export default {
		data() {
			return {
				formData: {},
				editorinfo:'',
				readOnly: false,
				videoData: [], //视频数据
			}
		},
		onLoad(options) {
			let _self = this;
			if (options && options.item) {
				_self.formData = JSON.parse(decodeURIComponent(options.item));
				request({
					url: Platform.api_requestUrl + '/system/notice/' + _self.formData.sysnoticeid,
					method: 'GET',
				}).then(response => {
					if (response.code == 200) {
						// 确保内容为HTML格式
						const content = response?.data?.noticeContent || '';
						_self.editorinfo = content;
						// 延迟执行编辑器初始化，确保DOM已经渲染
						setTimeout(() => {
							_self.onEditorReady();
						}, 100);
					} else {
						uni.showToast({
							title: '获取通知内容失败',
							icon: 'none'
						});
					}
				}).catch(error => {
					uni.showToast({
						title: '获取通知内容失败',
						icon: 'none'
					});
				});
			}
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			onEditorReady() {
				let _self = this;
				uni.createSelectorQuery().select('#editor').context((res) => {
					if (res && res.context) {
						this.editorCtx = res.context;
						// 确保内容不为空且为HTML格式
						if (_self.editorinfo) {
							this.editorCtx.setContents({
								html: _self.editorinfo
							});
						}
					} else {
						console.error('获取编辑器上下文失败');
					}
				}).exec();
			},
			onStatusChange(e) {
				const formats = e.detail
			}
		}
	}
</script>

<style lang='scss' scoped>
	.main-box {
		display: flex;
		flex-direction: column;
		margin: 16upx;
	}

	.header-bar {
		background: #f26522;
		height: 50px;
		display: flex;
		align-items: center;
		padding: 0 15px;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 999;
	}

	.back-icon {
		color: #fff;
		font-size: 24px;
		margin-right: 15px;
	}

	.header-title {
		color: #fff;
		font-size: 18px;
		font-weight: bold;
		flex: 1;
		text-align: center;
	}

	.main-box-header {
		margin-top: 50px;
		border-bottom-color: #E6E6E6;
		border-bottom-style: solid;
		border-bottom-width: 0.5px;
		padding: 10upx;

		.header-label {
			font-size: 20px;
			font-weight: bold;
			color: #333333;
		}

		.header-time {
			margin-top: 10px;
			right: 0px;
			font-size: 13px;
			font-weight: 400;
			color: #9a9a9a;
			text-align: right;
		}
	}

	.main-box-content {
		margin: 10upx 0;

		.content-value {
			height: 100%;

			#editor {
				height: 100%;
			}
		}
	}
</style>
